package com.taldh.design.patterns.observer.jdk;

import java.util.Observable;
import java.util.Observer;
import java.util.Random;

/**
 * date 2020/6/2
 *
 * @author 袁小黑
 * @version 1.0.0
 **/

class Weather extends Observable {

    WeatherType weatherType;

    Weather() {
        addObserver(new Sunwukong());
        addObserver(new Tangseng());
        weatherType = WeatherType.SUNNY;
    }

    public void timePasses() {
        weatherType = WeatherType.values()[new Random().nextInt(4)];
        System.out.println("Weather change to "+weatherType.toString());
        setChanged();
        notifyObservers(weatherType);
    }

}
